package com.noahplat.person.service.impl;

import com.noahplat.common.utils.Result;
import com.noahplat.common.utils.StatusCode;
import com.noahplat.person.mapper.HealthRecordMapper;
import com.noahplat.person.pojo.HealthRecord;
import com.noahplat.person.service.HealthRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

/**
 * @ClassName: HealthRecordServiceImpl
 * @Description: 体检报告实现类
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@Service
public class HealthRecordServiceImpl implements HealthRecordService {

    @Autowired
    private HealthRecordMapper healthRecordMapper;

    /**
     * 获取体检报告详情
     * @param id
     * @return
     */
    @Override
    public Result getHealthRecord(Long id) {
        Example example = new Example(HealthRecord.class);
        example.createCriteria().andEqualTo("id", id).andEqualTo("del", "N");
        HealthRecord healthRecord = healthRecordMapper.selectOneByExample(example);
        if(ObjectUtils.isEmpty(healthRecord)){
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
        return new Result(true, StatusCode.OK, "查询成功", healthRecord);
    }

    /**
     * 增加体检报告
     * @param healthRecord
     * @return
     */
    @Override
    public Result addHealthRecord(HealthRecord healthRecord) {
        int res = healthRecordMapper.insert(healthRecord);
        if(res > 0){
            return new Result(true, StatusCode.OK, "添加成功");
        }
        return new Result(false, StatusCode.ERROR, "添加失败");
    }

    /**
     * 更新体检报告/删除体检报告
     * @param healthRecord
     * @return
     */
    @Override
    public Result updateHealthRecord(HealthRecord healthRecord) {
        int res = healthRecordMapper.updateByPrimaryKeySelective(healthRecord);
        if(res > 0){
            return new Result(true, StatusCode.OK, "更新成功");
        }
        return new Result(false, StatusCode.ERROR, "更新失败");
    }
}
